package pers.jason.wppm.security.core.validate.code.processor.impl;

import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.ServletWebRequest;

import pers.jason.wppm.security.core.validate.code.SmsCode;
import pers.jason.wppm.security.core.validate.code.support.SimpleResponse;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class SmsValidateCodeProcessor extends AbstractValidateCodeTemplate<SmsCode> {

	private Logger logger = LoggerFactory.getLogger(getClass());

	private ObjectMapper objectMapper = new ObjectMapper();

	@Override
	protected void responseValidateCode(ServletWebRequest request, SmsCode code) throws IOException {
		// TODO Auto-generated method stub
		logger.info("发送验证码：" + code.getCode());
		HttpServletResponse response = request.getResponse();
		response.setContentType("application/json;charset=utf-8");
		response.getWriter().write(objectMapper.writeValueAsString(SimpleResponse.createSuccessResponse("已经发送")));
	}


	@Override
	public String getParamName() {
		return getSecurityProperties().getCode().getSms().getParamName();
	}
}
